<template>
	<view class="news">


		<view class="new_item">
					<view class="dtcll">
						<text>时间</text>
					</view>
					<view class="dtcll">
					<!-- 	<text>名称</text> -->
						<uni-data-picker placeholder="名称" popup-title="请选择名称" :localdata="dataName"
						 	 @nodeclick="onnodeclickName">
						 </uni-data-picker>
					</view>
					<view class="dtcll">
						<!-- <text>级别</text> -->
						<uni-data-picker placeholder="级别" popup-title="请选择级别" :localdata="dataLevel"
						 	 @nodeclick="onnodeclickLevel">
						 </uni-data-picker>
					</view>
					<view class="dtcll">
						<!-- <text>代码</text> -->
						<uni-data-picker placeholder="代码" popup-title="请选择代码" :localdata="dataCode"
						 	 @nodeclick="onnodeclickCode">
						 </uni-data-picker>
					</view>
					<view class="dtcll">
						<text>信息</text>
					</view>
				</view>
				
			<!-- <view>name:{{name}}</view>	
			<view>level:{{level}}</view>
			<view>code:{{code}}</view>
			<view>{{index}}</view> -->

		<view class="new_item"  v-for="(item,index) in activeArr" :key="item.id">
			<view class="cll">
				<!-- <text>{{item.showTimestamp}}</text> -->
				<text>{{item.create_timestamp | formatDate}}</text>
				
			</view>
			<view class="cll">
				<text>{{item.name}}</text>
			</view>
			<view class="cll">
				<text>{{item.level == 0 ? '通知' : ''}}{{item.level == 1 ? '警告' : ''}}{{item.level == 2 ? '异常' : ''}}{{item.level == 3 ? '错误' : ''}}</text>
			</view>
			<view  class="cll">
				<text>{{item.code}}</text>
			</view>
			<view  class="cll">
				<text>{{item.msg}}</text>
			</view>
			
		</view>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				name: '',
				code: '',
				level: '',
				index: 1,
				activeArr: [],
				flag: false,
				abc: [
					{
						showTimestamp: "",
						name: "#",
						level: "#",
						code: "#",
						msg: "#"
					}
				],

				dataName: [{
					text: "名称",
					value: "#",
				}],
				dataCode: [{
					text: "代码",
					value: "#",
				}],
				dataLevel: [{
					text: "级别",
					value: "#",
				}],
				
			}
		},
		methods: {
			async sendPost(){
				
				const res = await this.$myRequest({
					url: '/makerwit/wms/queryDCSAlarmInfoAndIndex',
					data: '{\"name\": \"'+this.name+'\",\"code\": \"'+this.code+'\",\"level\": \"'+this.level+'\",\"index\": \"'+this.index+'\"}',
					// data: '{\"name\": \"'+this.activeArr.name+'\",\"isInvalid\": 0}',
					method: 'POST'
				})
				console.log('=============================',res)
				this.activeArr =[...this.activeArr,...res.data.data] 
				
			},
			onnodeclickCode(e) {
				console.log('onnodeclick',e);
				this.code = e.value;
				this.index = 1;
				this.activeArr=[];
				this.sendPost();
			},
			onnodeclickName(e) {
				console.log('onnodeclick',e);
				this.name = e.value
				this.index = 1;
				this.activeArr=[];
				this.sendPost();
			},
			onnodeclickLevel(e) {
				console.log('onnodeclick',e);
				this.level = e.value
				this.index = 1;
				this.activeArr=[];
				this.sendPost();
			},
			async findAlarmCode(){
				const res = await this.$myRequest({
					url: '/makerwit/wms/findAlarmCode',
					data: '{}',
					method: 'POST'
				})
				console.log('AAAAAAAAAAAAAAAAAA',res.data.data[0])
				// for(let i = 0; i<res.data.data.length; i++){
				// 	res.data.data[i] = res.data.data[i]+',value = '+i
				// }
				// console.log(res.data.data[0])
				this.dataCode = [...this.dataCode,...res.data.data]
			},
			async findAlarmName(){
				const res = await this.$myRequest({
					url: '/makerwit/wms/findAlarmName',
					data: '{}',
					method: 'POST'
				})
				console.log('AAAAAAAAAAAAAAAAAA',res.data.data[0])
				// for(let i = 0; i<res.data.data.length; i++){
				// 	res.data.data[i] = res.data.data[i]+',value = '+i
				// }
				// console.log(res.data.data[0])
				this.dataName = [...this.dataName,...res.data.data]
			},
			async findAlarmLevel(){
				const res = await this.$myRequest({
					url: '/makerwit/wms/findAlarmLevel',
					data: '{}',
					method: 'POST'
				})
				console.log('AAAAAAAAAAAAAAAAAA',res.data.data[0])
				// for(let i = 0; i<res.data.data.length; i++){
				// 	res.data.data[i] = res.data.data[i]+',value = '+i
				// }
				// console.log(res.data.data[0])
				this.dataLevel = [...this.dataLevel,...res.data.data]
			},
		
		},
		onLoad() {
			this.sendPost();
			this.findAlarmCode()
			this.findAlarmName()
			this.findAlarmLevel()
			
		},
		onReachBottom() {
			// if(this.activeArr.length < 10*this.index)
			//用于判断触底时，当前页面的数据条数是否为最大条数，如果是，则禁止访问接口
			if(this.activeArr.length < 15*this.index) return this.flag = true
			console.log('触底了',this.index)
			this.index++
			this.sendPost()
			
		},
		filters: {
			formatDate: function (value) {
				let date = new Date(value);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h;
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m;
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s;
				return y + '-' + MM + '-' + d + '\n' + h + ':' + m + ':' + s;
			}
		}
		
	}
</script>

<style lang="scss">
	
.news{
	.new_item{
		display:flex;
		padding: 0 0;
		background-color: #FFFFFF;
		border-bottom: 1px solid #eeeeee;
		
		
		.cll{
			 width: 25%;
			height: 45px;			

		text{
			height: 45px;
		
			font-size: 25rpx;
			display: flex;
			  align-items: center;
			justify-content: center;

		}
		}

	}
}
.dtcll{
	width: 25%;
	height: 45px;	
	border: 1px solid #EEEEEE;
	text{
		height: 45px;
	
		font-size: 30rpx;
		display: flex;
		  align-items: center;
		justify-content: center;
	}
}

</style>
